Home:ALL Converter>File shared via AirDrop is incomplete

File shared via AirDrop is incomplete

Ask Time:2018-11-20T07:06:17         Author:Andrii Chernenko

Json Formatter

I am working on an application one of the features of which is downloading and displaying PDF files. I had no problems implementing these features. Then I wanted to enable sharing of the files but ran into a strange problem.

Here's how my sharing code looks like:

log.debug("Will share file: '\(fileURL.absoluteString)'")
// an example of fileURL: file:///var/mobile/Containers/Data/Application/3A6D5948-8F14-42FB-905A-D776BD975ED1/Library/Caches/d7e635bb-5baa-4fde-b60b-b3fb869cdf46/6.3%20Rambeskrivning%20Mark.pdf

let shareView = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
dependencies.router.show(shareView, asPopoverFrom: barButtonItem)

Nothing fancy, but when I share the file via AirDrop, it is only 200-250 bytes on the receiving end and has a different name, something like "PDF document-373E47D68169-1.pdf" (instead of the original name).

My first thought was that the downloaded document is corrupted, but it is not (I checked both on a device and a simulator). If I choose another sharing option (for instance, "Save to Files"), the file is shared correctly. UIDocumentInteractionController exhibits the same behavior. I also thought this might be caused by not retaining the UIActivityViewController (UIDocumentInteractionController requires this for the AirDrop sharing to work), but letting the system do this seems sufficient.

The issue is reproduced on both iOS 12.1 and 11.4.1.

What am I missing?

Author:Andrii Chernenko,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53383918/file-shared-via-airdrop-is-incomplete
yy